#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QDebug>
#include <QMainWindow>
#include <QThread>
#include <QWidget>
#include <QtWidgets/QPushButton>

#include <rclcpp/rclcpp.hpp>
#include <sensor_msgs/msg/imu.hpp>
// #include "std_msgs/msg/string.hpp"

// 线程类的声明
class imu_data_thread;
class imu_br_thread;
class Parameters;
class Parameters_updata;

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow {
  Q_OBJECT

public:
  explicit MainWindow(QWidget *parent = nullptr);
  ~MainWindow();
  QPushButton pushButton;
  QPushButton paramButton;


public slots:
  // pushButton的槽函数
  void On_allSelectBtnSlot();
  // imu信号
  void display_imu(double dis_r, double dis_p, double dis_y);
  // param
  void display_param(int dis_param);

private:
  Ui::MainWindow *ui;
  imu_data_thread *imu_data_Thread;
  imu_br_thread *imu_br_Thread;
  Parameters *parameters;
  Parameters_updata *parameters_updata;

signals:

  private slots:
  void on_paramButton_clicked();
};



// 订阅线程
class imu_data_thread : public QThread
{
  Q_OBJECT
public:
  rclcpp::Subscription<sensor_msgs::msg::Imu>::SharedPtr sub_;
  std::shared_ptr<rclcpp::Node> node;
  void ImuCallback(const sensor_msgs::msg::Imu::SharedPtr imu_data);

  imu_data_thread(QWidget *parent = nullptr) { Q_UNUSED(parent) };
  ~imu_data_thread() {}

  void run();

signals:
  void Data(double r_data, double p_data, double y_data);
};

// 广播线程
class imu_br_thread : public QThread
{
  Q_OBJECT

public:
  imu_br_thread(QWidget *parent = nullptr) { Q_UNUSED(parent) };
  ~imu_br_thread() {}
  void run();
};


// 读取参数线程
class Parameters : public QThread
{
    Q_OBJECT
public:
    std::shared_ptr<rclcpp::Node> Mynode_client;
    rclcpp::SyncParametersClient::SharedPtr param_client_;

    std::shared_ptr<rclcpp::ParameterEventHandler> param_subscriber_;
    std::shared_ptr<rclcpp::ParameterCallbackHandle> cb_handle_;



    Parameters(QWidget *parent = nullptr) { Q_UNUSED(parent) };
    ~Parameters() {}

    void run();

signals:
    void param_data(int param_data_);

// signals:

};

// 设置参数线程
class Parameters_updata : public QThread
{
    Q_OBJECT
public:
    std::shared_ptr<rclcpp::Node> updata_client;
    rclcpp::SyncParametersClient::SharedPtr param_client_updata;


    Parameters_updata(QWidget *parent = nullptr) { Q_UNUSED(parent) };
    ~Parameters_updata() {}

    void run();
    void setData(const QString &data)
        {
            data_ = data;
        }
public slots:

signals:

private:
    QString data_;

};

#endif // MAINWINDOW_H
